<template>
  <div>
    <el-button type="primary" @click="willAdd">添加</el-button>
    <!-- 表格组件 -->
    <v-list @willUpdate="willUpdate" :list="list" @init="init"></v-list>
    <!-- 弹框表单组件 -->
    <v-form :status="status" @init="init" :list="list" ref="from"></v-form>
  </div>
</template>

<script>
import vList from "./components/list.vue";
import vForm from "./components/form.vue";
import { reqmenulist } from "../../http/api";
export default {
  components: {
    vList,
    vForm,
  },
  data() {
    return {
      status: {
        isshow: false, //控制弹框出现与消失ture为出现
        isAdd: true, //控制弹框是点击添加出来的还是点击修改出来的，ture添加
      },
      list: [],
    };
  },
  methods: {
    willAdd() {
      this.status = {
        isshow: true,
        isAdd: true,
      };
    },
    willUpdate(id) {
      this.status = {
        isshow: true,
        isAdd: false,
      };
      this.$refs.from.getOne(id)
    },
    // 列表数据请求封装
    init() {
      reqmenulist({
        istree: true,
      }).then((res) => {
        this.list = res.data.list;
      });
    },
  },
  mounted() {
    this.init()
  },
};
</script>

<style>
</style>